import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;


public class UDPPrinter extends Thread{

	public int printerPort;
	private String serverIP;
	private int serverPort;
	
	public UDPPrinter(String serverIP, int serverPort, int printerPort)
	{
		this.serverIP = serverIP;
		this.serverPort = serverPort;
		this.printerPort = printerPort;
	}
	
	@Override
	public void run()
	{
		try {
			DatagramSocket socket = new DatagramSocket(this.printerPort);
				
			byte[] recvBuf = new byte[1024];
			DatagramPacket ansPacket = new DatagramPacket(recvBuf, 0, recvBuf.length);
			socket.receive(ansPacket);
			
			System.out.println("Printer: Recevied from Server" + new String(ansPacket.getData(), 0, ansPacket.getLength()));
	
			// Wait a bit before sending the next message.
			Thread.sleep(100);
					
		} catch (Exception e) {
		
			System.err.println("TCPClient-" + this.hashCode() + " exception: " + e);
			e.printStackTrace();
		}
	}
}
